import 'package:flutter/material.dart';

class SubNav extends StatefulWidget {
  final List subNavList;

  const SubNav({Key key, this.subNavList}) : super(key: key);

  @override
  _SubNavState createState() => _SubNavState();
}

class _SubNavState extends State<SubNav> {
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(6),
      ),
      child: Padding(
        padding: const EdgeInsets.all(7.0),
        child: _items(context),
      ),
    );
  }

  Widget _items(BuildContext context) {
    if (widget.subNavList == null) {
      return null;
    }
    int separate = (widget.subNavList.length / 2 + 0.5).toInt();
    List<Widget> list = [];
    widget.subNavList.forEach((element) {
      list.add(_item(context));
    });
    return Column(
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: list.sublist(0, separate),
        ),
        Padding(
          padding: const EdgeInsets.only(top: 10),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: list.sublist(separate, widget.subNavList.length),
          ),
        ),
      ],
    );
  }

  Widget _item(BuildContext context) {
    return Expanded(
      flex: 1,
      child: GestureDetector(
        onTap: () {
          print('object');
        },
        child: Column(
          children: [
            Image.asset(
              'images/Monthlycard.png',
              width: 18,
              height: 18,
            ),
            Padding(
              padding: const EdgeInsets.only(top: 3),
              child: Text('data', style: TextStyle(fontSize: 12)),
            ),
          ],
        ),
      ),
    );
  }
}
